package com.book.common.tree;

import com.google.common.collect.Sets;
import lombok.Data;
import lombok.ToString;

import java.io.Serializable;
import java.util.Set;

/**
 * Description：
 * @Author： leo.xiong
 * @CreateDate： 2019/10/14 13:47
 * @Email： leo.xiong@suyun360.com
 * Version：1.0
 */
@Data
@ToString
public class DataTree<T> implements Comparable<DataTree>, Serializable {
    private static final long serialVersionUID = -8185755305430775396L;
    /**
     * 树的最上级ID
     */
    public static final Long FIRST_INDEX_ID = 0L;
    /**
     * 树的最上层父级ID为空
     */
    public static final Long EMPTY_INDEX_ID = null;

    private Long id;

    private Long parentId;

    private Integer orderNum;

    private boolean checked = false;

    private boolean hasParent = false;

    private boolean hasChild = false;

    private Set<DataTree<T>> children = Sets.newTreeSet();

    private T data;

    @Override
    public int compareTo(DataTree o) {
        return this.orderNum > o.orderNum ? 1 : -1;
    }
}
